package com.zillion.web.controller.employ;

import com.zillion.common.core.controller.BaseController;
import com.zillion.common.core.domain.AjaxResult;
import com.zillion.employee.domain.EmployeeReserve;
import com.zillion.employee.domain.UnitReserve;
import com.zillion.employee.service.IEmployeeReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 从业人员个人/单位体检预约
 *
 * @author zillion
 */
@RestController
@RequestMapping("/employee/reserve")
public class EmployeeReserveController extends BaseController {

    @Autowired
    private IEmployeeReserveService employeeReserveService;

    /**
     * 根据身份证号获取申报信息
     */
    @GetMapping(value = "/{idCard}")
    public AjaxResult getInfoByIdCard(@PathVariable String idCard) {
        return success(employeeReserveService.selectApplyInfoByIdCard(idCard));
    }

    /**
     * 根据园区id获取对应的医院信息
     */
    @GetMapping(value = "/listHospital/{parkId}")
    public AjaxResult getHospitalsByParkId(@PathVariable Integer parkId) {
        return success(employeeReserveService.selectHospitalInfoByParkId(parkId));
    }

    /**
     * 获取所有医院信息
     * @return 医院信息
     */
    @GetMapping(value = "/listHospitals")
    public AjaxResult loadAllHospitals() {
        return success(employeeReserveService.loadAllHospitals());
    }

    /**
     * 获取所有医院地址信息
     * @return 医院地址信息
     */
    @GetMapping(value = "/listAddress")
    public AjaxResult loadAllHospitalAddress() {
        return success(employeeReserveService.loadAllHospitalAddress());
    }

    /**
     * 添加个人体检预约
     */
    @PostMapping("/addPerson")
    public AjaxResult addPeronReserve(@RequestBody EmployeeReserve employeeReserve) {
        int row = employeeReserveService.addPeronReserve(employeeReserve);
        // 没有添加数据,返回错误信息
        if (0==row) {
            return error("预约上传后，一年内不能再次预约！");
        }
        return success(row);
    }

    /**
     * 添加单位人员体检预约
     */
    @PostMapping("/addUnitPerson")
    public AjaxResult addUnitPersonReserve(@RequestBody UnitReserve unitReserve) {
        return success(employeeReserveService.addUnitPersonReserve(unitReserve));
    }

    /**
     * 根据身份证号获取申报信息
     */
    @GetMapping(value = "/unit/{socialCreditCode}")
    public AjaxResult getUnitReserveInfo(@PathVariable String socialCreditCode) {
        return success(employeeReserveService.getUnitReserveInfo(socialCreditCode));
    }

    @GetMapping(value = "/mine/loadUserProgress/{idCard}")
    public AjaxResult loadUserProgress(@PathVariable String idCard) {
        return success(employeeReserveService.loadUserProgress(idCard));
    }
}
